<?php
$wid = Session::get('wid');
$m = new Model('vshop_xcx_menu');
$m->find(array('wid'=>$wid));

$menu=$m->content;/********菜单json*****/
$bcg=json_decode($m->backgroundcolor,1);

$bc=$bcg['bc']?$bcg['bc']:'#DB384C';
$tc=$bcg['tc']?$bcg['tc']:'#DB384C';

$menus='[
      {
        "pagePath": "pages/index/index",
        "iconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/home_x200.png",
        "selectedIconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/home_select_x200.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/category/category",
        "iconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/category_x200.png",
        "selectedIconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/category_select_x200.png",
        "text": "分类"
      },
      {
        "pagePath": "pages/shoppingcart/shoppingcart",
        "iconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/cart_x200.png",
        "selectedIconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/cart_select_x200.png",
        "text": "购物车"
      },
      {
        "pagePath": "pages/usercenter/usercenter",
        "iconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/user_x200.png",
        "selectedIconPath": "http://'.$_SERVER['HTTP_HOST'].'/assets/wximg/user_select_x200.png",
        "text": "我的"
      },
	  {
        "pagePath": "",
        "iconPath": "",
        "selectedIconPath": "",
        "text": ""
      }
    ]';
$menus=$menu?$menu:$menus;
$menus=json_decode($menus,1);

if($m->try_post()){
	$m->wid = $wid;
	$m->createtime = time();
	
	$list = Request::post('list');
	$color = Request::post('color');
	
	$m->backgroundcolor=json_encode($color);
	$m->content=json_encode($list);
	$rs = $m->save();
	
	if($rs->id){
		$arr = array(
			'status' => 0,
			'message' => '保存成功',
			'url' => $url,
			'callback' => 'window.updateWidget('.$HomeId.')'
		);
	}else{
		$arr = array(
			'status' => 1,
			'message' => '保存失败',
			'url' => $url,
			'callback' => ''
		);
	}
	echo json_encode($arr);exit;
	
}
